package com.hzgj.bcl.soa.rpc;

import com.hzgj.bcl.soa.rpc.client.Response;
import com.hzgj.bcl.soa.rpc.message.Message;

public interface AsyncRequestHandler extends RequestHandler {

    /**
     * Invokes a request. This should be done <em>asynchronously</em>, e.g. by dispatching this to a thread pool.
     * When done, if a response is needed (e.g. in case of a sync RPC), {@link Response#send(Object, boolean)} should
     * be called.
     *
     * @param request  The request
     * @param response The response implementation. Contains information needed to handle the reply (e.g. a request ID).
     *                 If no response is required, e.g. because this is an asynchronous RPC, then response will be null.
     * @throws Exception If an exception is thrown (e.g. in case of an issue submitting the request to a thread pool,
     *                   the exception will be taken as return value and will be sent as a response. In this case,
     *                   {@link Response#send(Object, boolean)} must not be called
     */
    void handle(Message request, Response response) throws Exception;
}